From 552d6eaacad432a9422759705d93451e1a4561f5 Mon Sep 17 00:00:00 2001 From: robertl Date: Thu, 15 Sep 2005 01:53:04 +0000 Subject: [PATCH] Allow Natl Topo to allow override of datums for benefit of users in HI. --- gpsbabel/README | 6 ++++++ gpsbabel/jeeps/gpsmath.c | 13 +++++++++++++ gpsbabel/jeeps/gpsmath.h | 2 ++ gpsbabel/tpg.c | 25 ++++++++++++++++++++++--- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/gpsbabel/README b/gpsbabel/README index c6031e741..cba352a24 100644 --- a/gpsbabel/README +++ b/gpsbabel/README @@ -470,6 +470,12 @@ THE FORMATS National Geographic Topo! Waypoint Format. This filter reads and writes .TPG files created by various editions of NG Topo! This filter will *not* work with the newer combined .TPO files. + + The option 'datum="datum name"' can be used to override the + default of NAD27 ("N. America 1927 mean") which is correct + for the continental U.S. Points in Hawaii should use "Old + Hawaiian_mean" + Contributed by Alex Mottram. HOLUX diff --git a/gpsbabel/jeeps/gpsmath.c b/gpsbabel/jeeps/gpsmath.c index e3a9284a7..ac412f196 100644 --- a/gpsbabel/jeeps/gpsmath.c +++ b/gpsbabel/jeeps/gpsmath.c @@ -1797,3 +1797,16 @@ int32 GPS_Math_UTM_EN_To_WGS84(double *lat, double *lon, double E, return 1; } + +int32 GPS_Lookup_Datum_Index(const char *n) +{ + GPS_PDatum dp; + + for (dp = GPS_Datum; dp->name; dp++) { + if (0 == case_ignore_strcmp(dp->name, n)) { + return dp - GPS_Datum; + } + } + + return -1; +} diff --git a/gpsbabel/jeeps/gpsmath.h b/gpsbabel/jeeps/gpsmath.h index 4e2249f08..e308b8514 100644 --- a/gpsbabel/jeeps/gpsmath.h +++ b/gpsbabel/jeeps/gpsmath.h @@ -116,6 +116,8 @@ int32 GPS_Math_UTM_EN_To_WGS84(double *lat, double *lon, double E, int32 GPS_Math_UTM_EN_To_NAD83(double *lat, double *lon, double E, double N, int32 zone, char zc); +int32 GPS_Lookup_Datum_Index(const char *n); + #endif #ifdef __cplusplus diff --git a/gpsbabel/tpg.c b/gpsbabel/tpg.c index 81b80daf0..1c2022d42 100644 --- a/gpsbabel/tpg.c +++ b/gpsbabel/tpg.c @@ -33,9 +33,17 @@ static FILE *tpg_file_in; static FILE *tpg_file_out; static void *mkshort_handle; +static char *tpg_datum_opt; +static int tpg_datum_idx; static unsigned int waypt_out_count; +static +arglist_t tpg_args[] = { + {"datum", &tpg_datum_opt, "Datum (default=NAD27)", "N. America 1927 mean", ARGTYPE_STRING }, + {0, 0, 0, 0, 0} +}; + static int tpg_fread(void *buff, size_t size, size_t members, FILE * fp) { @@ -85,9 +93,19 @@ valid_tpg_header(char * header, int len) return memcmp(header_bytes, header, len); } +static void +tpg_common_init(void) +{ + tpg_datum_idx = GPS_Lookup_Datum_Index(tpg_datum_opt); + if (tpg_datum_idx < 0) { + fatal(MYNAME ": Datum '%s' is not recognized.\n", tpg_datum_opt); + } +} + static void tpg_rd_init(const char *fname) { + tpg_common_init(); tpg_file_in = xfopen(fname, "rb", MYNAME); } @@ -100,6 +118,7 @@ tpg_rd_deinit(void) static void tpg_wr_init(const char *fname) { + tpg_common_init(); tpg_file_out = xfopen(fname, "wb", MYNAME); mkshort_handle = mkshort_new_handle(); waypt_out_count = 0; @@ -172,7 +191,7 @@ tpg_read(void) &wpt_tmp->latitude, &wpt_tmp->longitude, &amt, - 78); + tpg_datum_idx); wpt_tmp->altitude = elev; @@ -255,7 +274,7 @@ tpg_waypt_pr(const waypoint *wpt) &lat, &lon, &amt, - 78); + tpg_datum_idx); /* swap the sign back *after* the datum conversion */ @@ -365,6 +384,6 @@ ff_vecs_t tpg_vecs = { tpg_read, tpg_write, NULL, - NULL, + tpg_args, CET_CHARSET_ASCII, 0 /* CET-REVIEW */ }; -- 2.30.2